package com.niit.schoolhub;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.junit.jupiter.api.Test;

import java.util.Collections;

public class SpeedCreate {
    @Test
    public void test(){
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create("jdbc:mysql://47.102.141.182:3306/liteluntan?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true", "root", "vbhgnmccw4672")
                .globalConfig(builder -> {
                    builder.author("kaguya") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(projectPath+"/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {

                    builder.parent("com.niit.schoolhub") // 设置父包名
                            .moduleName("system") // 设置父包模块名
                            .entity("pojo")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .mapper("mapper")
                            .xml("mapper.xml")
                            .other("utils")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath+"/src/main/resources/mapper/")); // 设置mapperXml生成路径
                })
                .templateConfig(builder -> {
                    builder.disable(TemplateType.ENTITY)
                            .entity("/templates/entity.java")
                            .service("templates/service.java")
                            .serviceImpl("templates/serviceImpl.java")
                            .mapper("templates/mapper.java")
                            .mapperXml("templates/mapper.xml")
                            .controller("templates/controller.java");
                })
                .strategyConfig(builder -> {
                    builder.addInclude("yesapi_bjy_comment","yesapi_bjy_link","yesapi_bjy_oauth_user","yesapi_one_article_tag","yesapi_one_articles","yesapi_one_category","yesapi_one_company","yesapi_one_medias","yesapi_one_tags","yesapi_one_users","yesapi_persistent_logins") // 设置需要生成的表名
                            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
                })
                .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
